﻿@model OnlineEducation.Data.Entities.Holiday
@{
    Layout = null;
}

@functions{

    List<SelectListItem>
    getYears()
    {
        List<SelectListItem>
            list = new List<SelectListItem>
                ();

        list.Add(new SelectListItem
        {
            Text = DateTime.Now.Year.ToString(),
            Value = DateTime.Now.Year.ToString(),
            Selected = true
        });
        list.Add(new SelectListItem
        {
            Text = DateTime.Now.AddYears(1).Year.ToString(),
            Value = DateTime.Now.AddYears(1).Year.ToString()
        });

        return list;



    }
    List<SelectListItem>
        getHolidays()
    {

        List<SelectListItem>
            list = new List<SelectListItem>
                ();
        list.Add(new SelectListItem
        {
            Text = "寒假",
            Value = "寒假"
        });
        list.Add(new SelectListItem
        {
            Text = "暑假",
            Value = "暑假"
        });
     

        list.Add(new SelectListItem
        {
            Text = "春节",
            Value = "春节"
        });
        list.Add(new SelectListItem
        {
            Text = "劳动节",
            Value = "劳动节"
        });
        list.Add(new SelectListItem
        {
            Text = "端午节",
            Value = "端午节"
        });
        list.Add(new SelectListItem
        {
            Text = "中秋节",
            Value = "中秋节"
        });
        list.Add(new SelectListItem
        {
            Text = "元旦",
            Value = "元旦"
        });

        return list;

    }

}


<div class="modal-header">
    @if (Model.Id != 0)
    {
        <h4 class="modal-title">修改</h4>
    }
    else
    {
        <h4 class="modal-title">新增</h4>
    }

    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<form onsubmit="return SubmitAddEdit(this)">
    <div class="modal-body p-4">

        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
        <input type="hidden" asp-for="Id" />

        <div class="row">
            <div class="col-md-12">

                <div class="form-group">
                    <label for="Year" class="control-label">年份</label>
                    @if (Model.Id != 0)
                    {
                        <input asp-for="Year" readonly="readonly" class="form-control" />
                    }
                    else
                    {
                        <select asp-for="Year" class="form-control" asp-items="getYears()"></select>
                        <span asp-validation-for="Year" class="text-danger"></span>
                    }
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label for="Name" class="control-label">假期</label>
                    @if (Model.Id != 0)
                    {
                        <input asp-for="Name" class="form-control" readonly="readonly" /> 

                    }
                    else
                    {
                        <select asp-for="Name" class="form-control" asp-items="getHolidays()"></select>
                        <span asp-validation-for="Name" class="text-danger"></span>
                    }

                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">

                <div class="form-group">
                    <label for="Range" class="control-label">开始日期-结束日期</label>
                    <input type="text" asp-for="Range" id="range-datepicker" class="form-control" placeholder="">
                    <span asp-validation-for="Range" class="text-danger"></span>

                </div>
            </div>
        </div>


        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label asp-for="Status" class="control-label">状态</label>
                    <select asp-for="Status" class="form-control" asp-items="Html.GetEnumSelectList<OnlineEducation.Enums.Status>()"></select>
                    <span asp-validation-for="Status" class="text-danger"></span>
                </div>
            </div>
        </div>

    </div>

    <div class="modal-footer">
        <button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">关闭</button>
        <button type="submit" class="btn btn-primary waves-effect waves-light">保存</button>
    </div>
</form>
<script>
    Ladda.bind('.btn-primary', { timeout: 1000 });

    $(function () {

        var year = $("#Year").val();

        var minDate = year + '-01-01';
        var maxDate = year + '-12-31';

        var month = new Date().getMonth() + 1;
        var day = new Date().getDate();


        var defaultDate = year + '-' + month + '-' + day;

        console.log(defaultDate);

        $("#range-datepicker").flatpickr({
            mode: "range",
            locale: "zh",
            minDate: minDate,
            maxDate: maxDate,
            //  defaultDate: defaultDate
        });


        $("#Year").change(function () {

            console.log($("#Year").val());

            var year = $("#Year").val();

            var minDate = year + '-01-01';
            var maxDate = year + '-12-31';

            var month = new Date().getMonth() + 1;
            var day = new Date().getDate();


            var defaultDate = year + '-' + month + '-' + day;

            console.log(defaultDate);

            $("#range-datepicker").flatpickr({
                mode: "range",
                locale: "zh",
                minDate: minDate,
                maxDate: maxDate,
                // defaultDate: defaultDate
            });



        });




    });
</script>



